﻿using System.Buffers.Text;
using Xunit;

namespace Unity.String.Tests.Buffers.Text
{
    public class FormattingHelpersTest
    {
        [Fact]
        public void MethodsTest()
        {
            Assert.Equal(6, FormattingHelpers.CountDigits(111111U));
            Assert.Equal(6, FormattingHelpers.CountDigits(101111U));
            Assert.Equal(6, FormattingHelpers.CountDigits(100111U));
            Assert.Equal(6, FormattingHelpers.CountDigits(100011U));
            Assert.Equal(6, FormattingHelpers.CountDigits(100001U));
            
            Assert.Equal(5, FormattingHelpers.CountDigits(11111U));
            Assert.Equal(4, FormattingHelpers.CountDigits(1111U));
            Assert.Equal(3, FormattingHelpers.CountDigits(111U));
            Assert.Equal(2, FormattingHelpers.CountDigits(11U));
            Assert.Equal(1, FormattingHelpers.CountDigits(1U));

            Assert.Equal(8, FormattingHelpers.CountDigits(11111111UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10111111UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10011111UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10001111UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10000111UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10000011UL));
            Assert.Equal(8, FormattingHelpers.CountDigits(10000001UL));
            
            Assert.Equal(7, FormattingHelpers.CountDigits(1111111UL));
            Assert.Equal(6, FormattingHelpers.CountDigits(111111UL));
            Assert.Equal(5, FormattingHelpers.CountDigits(11111UL));
            Assert.Equal(4, FormattingHelpers.CountDigits(1111UL));
            Assert.Equal(3, FormattingHelpers.CountDigits(111UL));
            Assert.Equal(2, FormattingHelpers.CountDigits(11UL));
            Assert.Equal(1, FormattingHelpers.CountDigits(1UL));
            Assert.Equal(14, FormattingHelpers.CountDigits(99999999999999UL));
            Assert.Equal(15, FormattingHelpers.CountDigits(100000000000001UL));
            
            Assert.Equal(2, FormattingHelpers.CountHexDigits(100U));
            Assert.Equal(5, FormattingHelpers.CountHexDigits(100001U));
            Assert.Equal(3, FormattingHelpers.CountHexDigits(1001UL));
            Assert.Equal(12, FormattingHelpers.CountHexDigits(99999999999999UL));
            Assert.Equal(12, FormattingHelpers.CountHexDigits(100000000000001UL));

            Assert.Equal(0, FormattingHelpers.CountDecimalTrailingZeros(0U, out var resultValue));
            Assert.Equal(0U, resultValue);
            
            Assert.Equal(2, FormattingHelpers.CountDecimalTrailingZeros(100U, out resultValue));
            Assert.Equal(1U, resultValue);
        }
        
    }
}